﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramUtilities
{
    public class Utils
    {
        public static bool exit()
        {
            bool valid = false;
            bool result = false;

            while (!valid)
            {
                string choice = GetString("Would you like to exit? y/n");

                if (choice.ToLower() == "y")
                {
                    result = true;
                    valid = true;
                }
                else if (choice.ToLower() == "n")
                {
                    valid = true;
                }
                else
                {
                    Console.WriteLine("Not valid. Input was: {0}",choice);
                }
            }

            return result;
        }

        public static string GetString(string prompt)
        {
            Console.WriteLine(prompt);
            return Console.ReadLine();
        }

        public static int GetNumber(string prompt)
        {
            int result = 0;
            bool valid = false;

            while (!valid)
            {
                try
                {
                    result = int.Parse(GetString(prompt));
                    valid = true;
                }
                catch
                {
                    Console.WriteLine("Not a Number");
                }
            }

            return result;
        }

        public static double GetDouble(string prompt)
        {
            double result = 0.0;
            bool valid = false;

            while (!valid)
            {
                try
                {
                    result = double.Parse(GetString(prompt));
                    valid = true;
                }
                catch
                {
                    Console.WriteLine("Not a Decimal");
                }
            }


            return result;
        }
    }
}
